package com.project.myPackage.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.project.myPackage.entity.Products;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

@Mapper
public interface ProductsMapper extends BaseMapper<Products> {
    // 根据用户id，获取收藏列表中的所有商品分类
    @Select("SELECT DISTINCT c.category_id " +
            "FROM products p " +
            "JOIN favorites f ON p.product_id = f.product_id " +
            "JOIN categories c ON p.category_id = c.category_id " +
            "WHERE f.user_id = #{user_id}")
    List<Integer> getFavoriteCategoriesByUserId(Integer user_id);

       @Select("<script>" +
        "SELECT * " +
        "FROM products " +
        "WHERE category_id IN " +
        "<foreach item='categoryId' index='index' collection='categoryIds' open='(' separator=',' close=')'>" +
        "#{categoryId}" +
        "</foreach>" +
        "AND status = 1" +
        "</script>")

      List<Products> getProductsByCategoryIds(@Param("categoryIds") Set<Integer> categoryIds);

}
